export const adminUrlApi = (url: string) => `/api/${url}`;

export interface Result {
  code: number;
  success: boolean;
  message: string;
  data?: Array<any>;
}
export function getFileName(contentDisposition) {
  let fileName = null;
  const matches = contentDisposition.match(
    /filename\*?=['"]?(?:UTF-\d['"]*)?([^;\n]*)['"]?/i
  );

  if (matches && matches[1]) {
    fileName = decodeURIComponent(matches[1]);
  } else {
    // 如果没有找到编码的文件名，则尝试直接取 filename= 后面的部分
    const dispositionArray = contentDisposition.split(";");
    for (let i = 0; i < dispositionArray.length; i++) {
      const disposition = dispositionArray[i].trim();
      if (disposition.startsWith("filename")) {
        fileName = disposition.split("=")[1].trim();
        break;
      }
    }
  }
  return fileName;
}

export interface ResultTable {
  success: boolean;
  data?: {
    map(arg0: (item: any) => { id: any; name: any }): unknown;
    filter(arg0: (item: any) => any): {
      /** 列表数据 */
      list: Array<any>;
      /** 总条目数 */
      total?: number;
      /** 每页显示条目个数 */
      pageSize?: number;
      /** 当前页数 */
      currentPage?: number;
    };
    /** 列表数据 */
    list: Array<any>;
    /** 总条目数 */
    total?: number;
    /** 每页显示条目个数 */
    pageSize?: number;
    /** 当前页数 */
    currentPage?: number;
  };
}
